/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AgregarEventos.java
 *
 * Created on 09-sep-2011, 9:45:24
 */
package Ventanas;

import DataTypes.DataEvento;
import Objetos.PropiedadesIP;
import Proxies.CtrlCrearGrupoWS;
import Proxies.CtrlCrearGrupoWSService;
import Proxies.CtrlUsuariosWS;
import Proxies.CtrlUsuariosWSService;
import Proxies.DataGrupoArray;
import Proxies.DataUsuarioArray;
import Proxies.EnumEvento;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.RowFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

/**
 *
 * @author jota
 */
public class AgregarEventos extends javax.swing.JFrame {

    CtrlUsuariosWS ctrlUsu;
    CtrlCrearGrupoWS ctrlCreG;
    private Calendar fecha = Calendar.getInstance();
    private ArrayList<String> diasDeSem = new ArrayList<String>();
  
    /** Creates new form AgregarEventos */
    public AgregarEventos() {
        initComponents();
        
        PropiedadesIP props = PropiedadesIP.getInstance();
        String IP = props.getServidorCentralIP();
        URL dirUsr = null;
        try {
            dirUsr = new URL(IP + "CtrlUsuarios?wsdl");
        } catch (MalformedURLException ex) {
            Logger.getLogger(AgregarEntradaMuro.class.getName()).log(Level.SEVERE, null, ex);
        }
        QName qNaUsr = new QName("http://WebServices/", "CtrlUsuariosWSService");
        ctrlUsu = new CtrlUsuariosWSService(dirUsr, qNaUsr).getCtrlUsuariosWSPort();
        
        URL dirGr = null;
        try {
            dirGr = new URL(IP + "CtrlCrearGrupo?wsdl");
        } catch (MalformedURLException ex) {
            Logger.getLogger(AgregarEntradaMuro.class.getName()).log(Level.SEVERE, null, ex);
        }
        QName qNaGr = new QName("http://WebServices/", "CtrlCrearGrupoWSService");
        ctrlCreG = new CtrlCrearGrupoWSService(dirGr, qNaGr).getCtrlCrearGrupoWSPort();
        
        buttonGroup1.add(vGrupo);
        buttonGroup1.add(vUsuario);
        Hora.setTargetDate(new Date(2000, 11, 27, 12, 00));
        HoraNoRep.setTargetDate(Calendar.getInstance().getTime());
        fechaNoRep.setTargetDate(Calendar.getInstance().getTime());
        this.add(jScrollBar1);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jScrollBar1 = new javax.swing.JScrollBar();
        jLabel1 = new javax.swing.JLabel();
        numEven = new javax.swing.JComboBox();
        vUsuario = new javax.swing.JRadioButton();
        vGrupo = new javax.swing.JRadioButton();
        vBuscar = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabla_Grupos = new javax.swing.JTable();
        buscar = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        NomEvent = new javax.swing.JTextField();
        vdia = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        diasEvent = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        fechaNoRep = new org.jbundle.thin.base.screen.jcalendarbutton.JCalendarButton();
        vCrear = new javax.swing.JButton();
        repetible = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        Hora = new org.sourceforge.jcalendarbutton.JTimeButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        HoraNoRep = new org.sourceforge.jcalendarbutton.JTimeButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        Table_Autor = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();

        jLabel1.setText("Nombre de Evento : ");

        numEven.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ANIVERSARIO", "RECORDATORIO", "REUNION" }));
        numEven.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                numEvenActionPerformed(evt);
            }
        });

        vUsuario.setText("Usuarios");
        vUsuario.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                vUsuarioFocusGained(evt);
            }
        });

        vGrupo.setText("Grupo");
        vGrupo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                vGrupoFocusGained(evt);
            }
        });

        vBuscar.setText("Elegir");
        vBuscar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                vBuscarMouseClicked(evt);
            }
        });

        tabla_Grupos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(tabla_Grupos);

        buscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                buscarKeyReleased(evt);
            }
        });

        jLabel3.setText("Buscar");

        vdia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado", "Domingo" }));
        vdia.setEnabled(false);

        jScrollPane1.setEnabled(false);

        diasEvent.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Dia", "Hora"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(diasEvent);

        jButton1.setText("Agregar");
        jButton1.setEnabled(false);
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        fechaNoRep.setText("Fecha");

        vCrear.setText("Crear");
        vCrear.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                vCrearMouseClicked(evt);
            }
        });

        repetible.setFont(new java.awt.Font("Times New Roman", 0, 14));
        repetible.setText("Repetible");
        repetible.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                repetibleMouseClicked(evt);
            }
        });
        repetible.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                repetibleActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 14));
        jLabel2.setText("Seleccionar Fecha del Evento (No Repetible)");

        Hora.setText("Hora");
        Hora.setEnabled(false);

        jLabel4.setText("DIA");

        jLabel5.setText("HORA");
        jLabel5.setEnabled(false);

        HoraNoRep.setText("Hora");

        Table_Autor.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nombre", "Nick", "Correo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane4.setViewportView(Table_Autor);

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel6.setText("Autor : ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(320, 320, 320)
                        .addComponent(jLabel1)
                        .addGap(1, 1, 1)
                        .addComponent(NomEvent, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(40, 40, 40)
                        .addComponent(numEven, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(60, 60, 60)
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(buscar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(90, 90, 90)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(repetible)
                                            .addGap(23, 23, 23))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                            .addComponent(jLabel6)
                                            .addGap(6, 6, 6)))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 290, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createSequentialGroup()
                                            .addGap(40, 40, 40)
                                            .addComponent(jLabel4)
                                            .addGap(30, 30, 30)
                                            .addComponent(vdia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(33, 33, 33)
                                            .addComponent(jLabel5)
                                            .addGap(11, 11, 11)
                                            .addComponent(Hora, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(80, 80, 80)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(220, 220, 220)
                                .addComponent(vCrear, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(vGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(vUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(80, 80, 80)
                        .addComponent(vBuscar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 206, Short.MAX_VALUE)
                        .addComponent(jLabel2)
                        .addGap(28, 28, 28)
                        .addComponent(fechaNoRep, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(HoraNoRep, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(109, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(NomEvent, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(numEven, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(vGrupo)
                            .addComponent(vUsuario))
                        .addGap(7, 7, 7)
                        .addComponent(vBuscar))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(fechaNoRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(HoraNoRep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel3)
                                .addComponent(buscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel6))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(210, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(repetible)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel4)
                                                .addComponent(vdia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(jLabel5)
                                            .addComponent(Hora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(20, 20, 20)
                                .addComponent(vCrear, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(15, 15, 15))))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void vBuscarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_vBuscarMouseClicked
        // TODO add your handling code here:
        
        if(vGrupo.isSelected())
        {
             Object[] fila = new Object[1];
            DataGrupoArray arr = ctrlCreG.listarGrupos();
           
            Iterator<Proxies.DataGrupo> itera = arr.getItem().iterator();
            Proxies.DataGrupo grp;
            DefaultTableModel model = (DefaultTableModel) tabla_Grupos.getModel();
            model.setRowCount(0);
            model.setColumnCount(1);
            while (itera.hasNext()) {
                grp = itera.next();
                fila[0] = grp.getNombre();
                model.addRow(fila);
            }
         
        }
        else if ( vUsuario.isSelected())
        {
            Object[] fila = new Object[3];
            DataUsuarioArray lis = ctrlUsu.listaUsuarios();
            
           Iterator<Proxies.DataUsuario> itera = lis.getItem().iterator();
            Proxies.DataUsuario usr;
            DefaultTableModel model = new DefaultTableModel();
            tabla_Grupos.setModel(model);
            
            model.addColumn("Nombre");
            model.addColumn("Nick");
            model.addColumn("Correo");
            model.setRowCount(0);
            tabla_Grupos.setRowSelectionAllowed(true);
            tabla_Grupos.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        
            while (itera.hasNext()) {
                usr = itera.next();
                fila[0] = usr.getNombre();
                fila[1] = usr.getNick();
                fila[2] = usr.getCorreo();
                model.addRow(fila);
                
            }
         
           
        }
        
            DefaultTableModel modelA = new DefaultTableModel();
            Object[] fila = new Object[3];
            DataUsuarioArray listarDUsuarios = ctrlUsu.listaUsuarios();
            Iterator<Proxies.DataUsuario> itera = listarDUsuarios.getItem().iterator();
            Proxies.DataUsuario usr;
           
            Table_Autor.setModel(modelA);
            
            modelA.addColumn("Nombre");
            modelA.addColumn("Nick");
            modelA.addColumn("Correo");
            modelA.setRowCount(0);
            Table_Autor.setRowSelectionAllowed(true);
            Table_Autor.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        
            while (itera.hasNext()) {
                usr = itera.next();
                fila[0] = usr.getNombre();
                fila[1] = usr.getNick();
                fila[2] = usr.getCorreo();
                modelA.addRow(fila);
                
            }
            Table_Autor.setRowSelectionInterval(0,0);
          
      
         
    }//GEN-LAST:event_vBuscarMouseClicked

    private void vGrupoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_vGrupoFocusGained
        // TODO add your handling code here:
      
    }//GEN-LAST:event_vGrupoFocusGained

    private void vUsuarioFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_vUsuarioFocusGained
        // TODO add your handling code here:
     
    }//GEN-LAST:event_vUsuarioFocusGained

    private void buscarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_buscarKeyReleased
        // TODO add your handling code here:
        TableModel modelo = tabla_Grupos.getModel();
        final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(modelo);
        tabla_Grupos.setRowSorter(sorter);
        String text = buscar.getText();
        if (text.length() == 0) {
          sorter.setRowFilter(null);
        } else {
          sorter.setRowFilter(RowFilter.regexFilter(text));
          
        }
       
        
    }//GEN-LAST:event_buscarKeyReleased

    private void numEvenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numEvenActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_numEvenActionPerformed

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        // TODO add your handling code here:
        Calendar cal = Calendar.getInstance();
             
        if(repetible.isSelected())
        {
        
        DefaultTableModel model = (DefaultTableModel) diasEvent.getModel();
        Object[] fila = new Object[2];
        String dia,h;
        cal.setTime(Hora.getTargetDate());
//        cal2.setTime(repFecha.getTargetDate());
//        cal2.set(cal2.get(Calendar.YEAR), cal2.get(Calendar.MONTH),cal2.get(Calendar.DATE),cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE));
        fecha = cal;
        diasDeSem.add(vdia.getSelectedItem().toString()+ "  A las: "+cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE));
        
        fila[0]= vdia.getSelectedItem().toString();
        fila[1] = cal.getTime().toString().substring(10, 16);
        model.addRow(fila);
        }
        else JOptionPane.showMessageDialog(null, "Debe Elegir Repetible");
        
        
    }//GEN-LAST:event_jButton1MouseClicked

    private void vCrearMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_vCrearMouseClicked
        // TODO add your handling code here:
         if(tabla_Grupos.getModel().getRowCount()==0)
         {JOptionPane.showMessageDialog(null, "Debe selecionar un Grupo o Usuario");
            return;
         }
        
                
        String nomUsuario;
        int col=0;
        if(vUsuario.isSelected())
            col=2;
        if (tabla_Grupos.getSelectedRow() == -1) {
            nomUsuario = tabla_Grupos.getValueAt(0,col).toString();
        } else {
            nomUsuario = tabla_Grupos.getValueAt(tabla_Grupos.getSelectedRow(),col).toString();
        }
        
        EnumEvento tipoEv = EnumEvento.valueOf(numEven.getSelectedItem().toString());
        
        
//       DataEvento ev = new DataEvento();
//       ev.setNombre(NomEvent.getText());
//       ev.setTipo(tipoEv);
//       ev.setRepetible(repetible.isSelected());
//       ev.setFecha(fecha);
//       ev.setDiasDeSemana(diasDeSem);
       String autor = Table_Autor.getValueAt(Table_Autor.getSelectedRow(),2).toString();
//       ev.setAutor(Factory.getInstance().getUsuarios().getUsuario(autor));
      
       PropiedadesIP props = PropiedadesIP.getInstance();
        String IP = props.getServidorCentralIP();
        URL dirUsr = null;
        try {
            dirUsr = new URL(IP + "CtrlUsuarios?wsdl");
        } catch (MalformedURLException ex) {
            Logger.getLogger(AgregarEntradaMuro.class.getName()).log(Level.SEVERE, null, ex);
        }
        QName qNaUsr = new QName("http://WebServices/", "CtrlUsuariosWSService");
        ctrlUsu = new CtrlUsuariosWSService(dirUsr, qNaUsr).getCtrlUsuariosWSPort();
       
        Proxies.DataEvento datE = new Proxies.DataEvento();
        datE.setAutor(ctrlUsu.getUsuario(autor));
        if (!repetible.isSelected()) {
            Calendar cal = Calendar.getInstance();
            int hora = HoraNoRep.getTargetDate().getHours();
            int min = HoraNoRep.getTargetDate().getMinutes();
            cal.setTime(fechaNoRep.getTargetDate());
            cal.set(Calendar.MINUTE, min);
            cal.set(Calendar.HOUR, hora);
            fecha = cal;
            GregorianCalendar c = new GregorianCalendar();
            c.setTime(fecha.getTime());
            try {
                XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
                datE.setFecha(date);
            } catch (DatatypeConfigurationException ex) {
                Logger.getLogger(AgregarEventos.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
       datE.setNombre(NomEvent.getText());
       datE.setTipo(tipoEv);
       datE.setRepetible(repetible.isSelected());
       datE.getDiasDeSemana().addAll(diasDeSem);
       
        
       if(vUsuario.isSelected())
            ctrlUsu.agregarEvento(datE,nomUsuario);
       if(vGrupo.isSelected())
            ctrlCreG.agregarEvento(datE, nomUsuario);
           
       JOptionPane.showMessageDialog(null, "Se Agrego correctamente");
   
    }//GEN-LAST:event_vCrearMouseClicked

    private void repetibleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_repetibleActionPerformed
        // TODO add your handling code here:
        
    }//GEN-LAST:event_repetibleActionPerformed

    private void repetibleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_repetibleMouseClicked
        // TODO add your handling code here:
        if(repetible.isSelected())
        {
           vdia.setEnabled(true);
           Hora.setEnabled(true);
           jButton1.setEnabled(true);
        }
    }//GEN-LAST:event_repetibleMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AgregarEventos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AgregarEventos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AgregarEventos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AgregarEventos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new AgregarEventos().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.sourceforge.jcalendarbutton.JTimeButton Hora;
    private org.sourceforge.jcalendarbutton.JTimeButton HoraNoRep;
    private javax.swing.JTextField NomEvent;
    private javax.swing.JTable Table_Autor;
    private javax.swing.JTextField buscar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JTable diasEvent;
    private org.jbundle.thin.base.screen.jcalendarbutton.JCalendarButton fechaNoRep;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollBar jScrollBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JComboBox numEven;
    private javax.swing.JRadioButton repetible;
    private javax.swing.JTable tabla_Grupos;
    private javax.swing.JButton vBuscar;
    private javax.swing.JButton vCrear;
    private javax.swing.JRadioButton vGrupo;
    private javax.swing.JRadioButton vUsuario;
    private javax.swing.JComboBox vdia;
    // End of variables declaration//GEN-END:variables
}
